import { defineStore } from 'pinia'
import type { System } from '@/store/interface'
import { SYSTEM } from '@/store/constant/cacheKey'

export const useSystemInfo = defineStore('systemInfo', {
  state: (): System => ({
    token: '',
  }),
  actions: {
    dataFill(state: System) {
      this.$state = { ...this.$state, ...state }
    },
    setToken(token: string) {
      this.token = token
    },
    getToken() {
      return this.token
    },
    removeToken() {
      this.token = ''
    },

    clear() {
      this.token = ''
    },
    isLogin() {
      return this.token
    },
  },
  persist: {
    key: SYSTEM,
    storage: sessionStorage, // 存储方式
  },
})
